package com.sgb.jicai.view.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.jicai.R;
import com.sgb.jicai.entity.JcMyJoinFactoryListEntity;
import com.swgk.core.BR;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MDateUtil;

import java.util.List;

public class CenterMyJoinFactoryAdapter extends BaseRecycleAdapter<JcMyJoinFactoryListEntity> {

    private Context context;
    private ExitListerner exitListener;

    public CenterMyJoinFactoryAdapter(Context context, List<JcMyJoinFactoryListEntity> datas) {
        super(context, R.layout.item_center_myjoin_factory, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, JcMyJoinFactoryListEntity jcMyFactoryListEntity) {
        holder.setBinding(BR.viewModel, jcMyFactoryListEntity);
        TextView tvCreatTime = holder.itemView.findViewById(R.id.tv_create_time);
        tvCreatTime.setText(MDateUtil.getYMDHSDate(jcMyFactoryListEntity.getCreateTime()));
        TextView tvQuit = holder.itemView.findViewById(R.id.tv_quit);
        TextView tvDelete = holder.itemView.findViewById(R.id.tv_delete);
        ImageView ivStatus = holder.itemView.findViewById(R.id.iv_status);
        if (jcMyFactoryListEntity.getStatus().equals("1")) {//集采中
            ivStatus.setBackground(context.getResources().getDrawable(R.mipmap.collect_ing));
            tvQuit.setVisibility(View.VISIBLE);
            tvDelete.setVisibility(View.GONE);
        } else {//集采结束
            ivStatus.setBackground(context.getResources().getDrawable(R.mipmap.collect_complate));
            tvQuit.setVisibility(View.GONE);
            tvDelete.setVisibility(View.VISIBLE);
        }
        tvQuit.setOnClickListener(view -> {
            if (null != exitListener) {
                exitListener.quitJc(jcMyFactoryListEntity);
            }
        });
        tvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != exitListener) {
                    exitListener.DeleteJc(jcMyFactoryListEntity);
                }
            }
        });
    }

    public interface ExitListerner {
        void quitJc(JcMyJoinFactoryListEntity entity);
        void DeleteJc(JcMyJoinFactoryListEntity entity);
    }

    public void setExitListerner(ExitListerner listener) {
        this.exitListener = listener;
    }


}
